﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter24.Examples
{
    using Databases;
    public class Code02
    {
        public static void BeginEx02()
        {
            var entities = new AdventureWorks2008Entities();
            var queryResults =
                from c in entities.AddressTypes
                select new
                {
                    ID = c.AddressTypeID,
                    Name = c.Name,
                    ModifiedDate = c.ModifiedDate,
                    BusinessEntityAddresses = c.BusinessEntityAddresses
                };
            foreach (var item in queryResults)
            {
                Console.WriteLine("AddressTypes: {0} {1}, {2}\n" +
                    "{3} BusinessEntityAddresses: \tID\tAddress, Before 5s",
                    item.ID, item.Name, item.ModifiedDate, item.BusinessEntityAddresses.Count);
                foreach (var business in item.BusinessEntityAddresses.Take(5))
                {
                    Console.WriteLine("\t\t\t\t{0}\t{1}", business.AddressID, business.Address.AddressLine1);
                }
                Console.WriteLine();
            }
            Console.WriteLine("Press Enter/Return to continue...");
            Console.ReadLine();
        }
    }
}
